﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using LitJson;

public class Regist : MonoBehaviour {

    public static Regist Instance;

    public InputField name_input;

    public InputField pass_input;

    public InputField nechen_input;

    public InputField tuijian_input;

    public Toggle manToggle;

    public Toggle womenToggle;

    void Awake()
    {
        Instance = this;

    }

    void OnEnable()
    {
        NotficationCenter.Instance.AddNotificationEvent(ClientPoll.pollEvent.Regist_Back_Event.ToString(),RegistBack);
    }

    void OnDisable()
    {
        NotficationCenter.Instance.RemoveNotificationEvent(ClientPoll.pollEvent.Regist_Back_Event.ToString(), RegistBack);
    }

  public void RegistBack(Notification node)
    {
        Debug.LogError("注册返回 ====>" + (string)node.data);
        this.gameObject.SetActive(false);
        StartUIMgr.Instance.LoginUI_Show();
    }

    public void OKLoginClicked()
    {
        if (GetName == null || GetPassword == null || GetNeChen == null || GetTuijian == null || GetName == "" || GetPassword == "" || GetNeChen == "" || GetTuijian == "")
        {
            Debug.LogError("请输入完全才能注册...");
            return;
        }

        JSONClass jd = new JSONClass();
        jd["cmd"] = ((int)ClientPoll.pollEvent.Regist_Back_Event).ToString();
        jd["name"] = GetName;
        jd["password"] = GetPassword;
        jd["repassword"] = GetPassword;
        jd["nickname"] = GetNeChen;
        jd["sex"] = GetSex.ToString();
        Debug.LogError("注册请求=============>>>" + jd.ToString());
        //ClientTcp.Instance.SendMessage(jd.ToString());
       
    }

    //获取性别
    public int GetSex
    {
        get
        {
            if (manToggle.isOn)
            {
                return 1;
            }
            else return 0;
        }
    }

    /// <summary>
    /// 获取名字输入
    /// </summary>
    public string GetName
    {
        get
        {
            return name_input.text;
        }
    }

    /// <summary>
    /// 获取密码输入
    /// </summary>
    public string GetPassword
    {
        get
        {
            return pass_input.text;
        }
    }

    /// <summary>
    /// 获取呢称输入
    /// </summary>
    public string GetNeChen
    {
        get
        {
            return nechen_input.text;
        }
    }

    /// <summary>
    /// 获取推荐码输入
    /// </summary>
    public string GetTuijian
    {
        get
        {
            return tuijian_input.text;
        }
    }

}
